package digitNotFound;

import java.util.HashMap;

import java.util.Scanner;

class DigitNotFound extends Exception{
    public DigitNotFound(String message) {
        super(message);
    }
}

class Digit{

    public static String digit(String str) throws DigitNotFound {

        char[] arr=str.toCharArray();

        HashMap<Character,Integer>hm=new HashMap<>();

        for(char ch:arr){
            if((int)ch>=(int)'0'&&(int)ch<=(int)'9'){
                hm.put(ch,1+hm.getOrDefault(ch,0));
            }
        }
        StringBuilder sb=new StringBuilder();
        int zerosNum=hm.getOrDefault('0',0);

        for(int i=1;i<10;i++){
            for(int j=0;j<hm.getOrDefault((char)(i+'0'),0);j++){
                sb.append((char)(i+'0'));
            }
        }
        if(sb.isEmpty()){
            if(hm.getOrDefault('0',0)==0){
                throw new DigitNotFound("digit not found");
            }else{
                return "0";
            }
        }

        for(int i=0;i<zerosNum;i++){
            sb.append('0');
        }
        String result=new String(sb);
        if(str.isEmpty()){
            throw new DigitNotFound("digit not found");
        }

        return result;
    }

}

public class Main {
    public static void main(String[] args){
        String str="";
        Scanner sc=new Scanner(System.in);
        System.out.println("输入字符串。输入exit时结束");
        while(!str.equals("exit")){
            str=sc.nextLine();
            try{
                String result=Digit.digit(str);
                if(!result.isEmpty()){
                    System.out.println(str);
                }
            }
            catch(DigitNotFound e) {
                System.out.println("异常：" + e.getMessage());
            }
        }

        sc.close();
    }
}

